package com.xyhuo.leetcode;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

public class FindRepeatedDnaSequences {
    public List<String> findRepeatedDnaSequences(String s) {
        if (s.length() < 10) {
            return new ArrayList<>();
        }
        char[] charArray = s.toCharArray();

        Set<String> set = new HashSet<>();
        List<String> result = new ArrayList<>();
        for (int i = 0; i <= charArray.length - 10; i++) {
            String tmp = s.substring(i, i + 10);
            if (set.contains(tmp)) {
                result.add(tmp);
            } else {
                set.add(tmp);
            }
        }

        return result.stream().distinct().collect(Collectors.toList());
    }
}
